package com.dpiinc.TechPage.pen.dialog;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.dpiinc.TechPage.R;

import org.jetbrains.annotations.Nullable;

/**
 * Created by hu489_000 on 2018-07-23.
 */

public class ServiceDialog extends BaseFloatDialog {

    public interface OnClickEditListener {
        void onClickOK();
    }

    private static OnClickEditListener onClickEditListener;

    private static ServiceDialog mServiceDialog;

    private Context mContext;

    public ServiceDialog(@Nullable Context context, OnClickEditListener onClickEditListener) {
        super(context);
        this.onClickEditListener = onClickEditListener;
    }



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_service_agreement);

    }

    public static void ShowDialog(@Nullable final Context context, final String title , final String msg, final OnClickEditListener onListener) {

        new Handler().post(new Runnable() {
            @Override
            public void run() {
                mServiceDialog = new ServiceDialog(context,onListener);
                mServiceDialog.show();
                TextView tv_title = mServiceDialog.findViewById(R.id.tv_title);
                tv_title.setText(title);
                TextView tv_msg = mServiceDialog.findViewById(R.id.tv_msg);
                tv_msg.setText(msg);
                Button btn_ok = mServiceDialog.findViewById(R.id.btn_ok);
                btn_ok.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        onClickEditListener.onClickOK();
                    }
                });
                Button btn_cancel = mServiceDialog.findViewById(R.id.btn_cancel);
                btn_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                      dismissDialog();
                    }
                });
            }
        });



    }

    public static void dismissDialog() {
        if (mServiceDialog != null && mServiceDialog.isShowing()) {
            mServiceDialog.dismiss();
        }
    }
}
